<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/cms/include/init_admin.jsp" %>
<%@ page import="com.qbooks.cms.product.*" %>
<%
	HashList code001		= CommonUtil.getCodeList("001");	//앱종류
	HashList code010		= CommonUtil.getCodeList("010");	//무료구분
	HashList code011		= CommonUtil.getCodeList("011");	//무료구분
	HashList code012		= CommonUtil.getCodeList("012");	//소개형식
	HashList code017		= CommonUtil.getCodeList("017");	//판매상태
	HashList codeCategory	= CommonUtil.getCodeList("category");	//카테고리

	String tabs_code		= StringUtil.nvl(request.getParameter("tabs_code"), "1");
	String job_type			= StringUtil.nvl(request.getParameter("job_type"),"U");
	String book_code		= StringUtil.nvl(request.getParameter("book_code"));

	HashMap infos 		= new HashMap();
	infos.put("book_code",	book_code);

	ProductDAO dao 	= new ProductDAO();
	HashList list 	= dao.selectBookInfo(infos);
	HashList countList = new HashList();	//dao.selectBookCountInfo(infos);
	
	HashList reviewList = dao.selectReviewList(infos);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= SYSTEM_NAME %></title>
	<%@ include file="/cms/include/cssnjs.jsp"  %>
	<script type="text/javascript" src="/js/ajaxfileupload.js"></script>
	<script type="text/javascript" src="/SE2.3.1.O9858/js/HuskyEZCreator.js" charset="utf-8"></script>

	<script type="text/javascript">
	var oEditors = [];

	$(document).ready(function() {

		$('#publish_dt').mask('9999.99.99').datepicker();
		
		//cfInitSE("intro");
		//cfInitSE("index_info");
		//cfInitSE("author_info");

		/* 탭 초기화 */
		$('#tabs li[code="<%=tabs_code%>"]').removeClass('off').addClass('on');
		$('#tabs-<%=tabs_code%>').removeClass('hidden');
		
		/* 탭 클릭 */
		$('li', '#tabs').click(function(){
		    $('.on', '#tabs').removeClass('on').addClass('off');
		    $(this).addClass('on');

			$('#tabs-1:not(.hidden),#tabs-2:not(.hidden),#tabs-3:not(.hidden),#tabs-4:not(.hidden),#tabs-5:not(.hidden)').addClass('hidden');
			$('#tabs-'+$(this).attr('code')).removeClass('hidden');
		});


	});


	function fnSave() {

		if (confirm(MSG_<%=job_type%>)) 
		{
			//oEditors.getById["intro"].exec("UPDATE_CONTENTS_FIELD", []);
			//oEditors.getById["index_info"].exec("UPDATE_CONTENTS_FIELD", []);
			//oEditors.getById["author_info"].exec("UPDATE_CONTENTS_FIELD", []);
			
			$('#saveForm').attr('action', './bookSave.do');
			$('#saveForm').submit();
		}
	}


	function fnDelete() {
		if (confirm(MSG_D)) {
			$('#job_type').val('D');
			$('#saveForm').attr('action', './bookSave.do');
			$('#saveForm').submit();
		}
	}
	
	
	function fnDeleteReview(member_id, book_code) {
		if (confirm(MSG_DELETE)) {
			$.ajax({
				url: './reviewSave.do',
				type: "POST",
			    dataType: 'json',//html,text,json
			    data: { //파라미터
			    	job_type : 'D',
			    	member_id : member_id,
			    	book_code : book_code
			    },
			    error: function(data, status, err){
			    	alert(err);
			    },
				success: function(data){
					if (data.result) {
						fnLoadReview();
					} else {
						alert(data.message);
					}
			    }
			});
		}
	}
	
	function fnLoadReview() {
		$('#reviewList').html('');
		$('#reviewList').load('./bookReviewList.jsp?book_code=<%=book_code%>', '', function() {
		});
	}



	</script>
</head>
<body>
<div id="wrap">
	<div id="top">
		<%@ include file="/cms/include/top.jsp" %>
	</div>
	<div id="page">
		<div id="menu">
			<%@ include file="/cms/include/leftMenu.jsp" %>
		</div>
		<div id="contents">
			<div class="menu_title">
				<h1>큐북관리</h1>
				<p>CMS > 상품관리  > <b>큐북관리</b></p>
			</div>
			<div class="clear line_01"></div>

			<ul id="tabs" class="tab_01 mt15">
			    <li class="off" code="1"><p>1. 기본사항</p></li>
			    <li class="off" code="2"><p>2. 책소개</p></li>
			    <li class="off" code="3"><p>3. 목차</p></li>
			    <li class="off" code="4"><p>4. 저자소개</p></li>
			    <li class="off" code="5"><p>5. 리뷰(<%= reviewList.size() %>)</p></li>
			    <li class="off" code="6"><p>6. 판매내역</p></li>
			</ul>


			<form id="saveForm" name="saveForm" enctype="multipart/form-data"  method="post" action="">
			<input type="hidden" name="job_type" id="job_type" value="<%= job_type %>"/>
			<input type="hidden" name="book_code" value="<%= book_code %>"/>

			<div id="tabs-1" class="mt15">

				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="120px"/>
					<col width="200px"/>
					<col width="120px"/>
					<col width="200px"/>
					<col width="120px"/>
					<col/>
				</colgroup>
				<tbody>
					<tr>
						<th><p>큐북코드</p></th>
						<td>
							
						<% if ("C".equals(job_type)) { %>
							<input type="text" name="book_code" maxlength="16"  value=""  class="w120"/>
						<% } else { %>
							<input type="hidden" name="book_code" value="<%= list.get("book_code", 0) %>" />
							<%= list.get("book_code",0) %>
						<% } %>
						</td>
						<th><p>발행자ID<span class="required">*</span></p></th>
						<td>
							<input type="text" name="publisher_id" value="<%= list.get("publisher_id", 0) %>" maxlength="12" class="w100"/>
						</td>
						<th><p>판매상태</p></th>
						<td class="brx">
							<select name="sales_status" class="w100">
							<%= StringUtil.makeOption(code017, list.get("sales_status", 0)) %>
							</select>
						</td>
					</tr>
					<tr>
						<th><p>큐북명<span class="required">*</span></p></th>
						<td colspan="5" class="brx">
							<input type="text" name="book_name" value="<%= list.get("book_name", 0) %>"  class="wmax"/>
						</td>
					</tr>
					<tr>
						<th><p>소제목</p></th>
						<td colspan="5" class="brx">
							<input type="text" name="sub_title" value="<%= list.get("sub_title", 0) %>"  class="wmax"/>
						</td>
					</tr>
					<tr>
						<th rowspan="7"><p>표지이미지</p></th>
						<td rowspan="7" >
							<input type="file" name="book_image_url" value="" class="input_file wmax" />
							<div class="mt5">
			        		<a href="<%= list.get("book_image_url",0) %>" target="_blank"><img src="<%= list.get("book_image_url",0) %>" width="160px"/></a>
			        		</div>
						</td>
						<th><p>앱종류<span class="required">*</span></p></th>
						<td>
							<%= StringUtil.makeRadio(code001, "app_type", list.get("app_type",0)) %>
						</td>
	        			<th><p>카테고리<span class="required">*</span></p></th>
						<td class="brx">
							<select name="category_code">
							<%= StringUtil.makeOptionByGroup(codeCategory, list.get("category_code", 0)) %>
							</select>
	        			</td>
					</tr>
					<tr>
						<th><p>출판사명</p></th>
						<td>
							<input type="text" name="publisher_name" value="<%= list.get("publisher_name",0) %>" class="wmax"/>
	        			</td>
						<th><p>발매일</p></th>
						<td class="brx">
							<input type="text" name="publish_dt" id="publish_dt" value="<%= list.get("publish_dt", 0) %>"  class="w90 c"/>
	        			</td>
					</tr>
					<tr>
						<th><p>저자명</p></th>
						<td>
							<input type="text" name="author_name" value="<%= list.get("author_name", 0) %>"  class="wmax"/>
	        			</td>
	        			<th><p>조회수</p></th>
						<td class="brx">
							<%= list.get("hit_count", 0) %>
	        			</td>
	        		</tr>
	        		<tr>
						<th><p>페이지수<span class="required">*</span></p></th>
						<td>
							<input type="text" name="page_count" value="<%= list.get("page_count", 0) %>"  class="w60 r"/> 페이지
	        			</td>
						<th><p></p></th>
						<td class="brx">
							
	        			</td>
	        		</tr>
	        		<tr>
						<th><p>ISBN</p></th>
						<td>
							<input type="text" name="isbn" value="<%= list.get("isbn", 0) %>"  class="wmax"/>
	        			</td>
						<th><p>ECN</p></th>
						<td class="brx">
							<input type="text" name="ecn" value="<%= list.get("ecn", 0) %>"  class="wmax"/>
	        			</td>
					</tr>
	        		<tr>
						<th><p>판매구분<span class="required">*</span></p></th>
						<td>
							<%= StringUtil.makeRadio(code010, "book_type", list.get("book_type",0)) %>
						</td>
						<th><p>판매가</p></th>
						<td class="brx">
							<input type="text" name="price" value="<%= list.get("price", 0) %>"  class="w60 r"/> 원
						</td>
	        		</tr>
	        		<tr>
	        			<th><p>아이템코드<span class="remark">(아이폰)</span></p></th>
						<td>
							<input type="text" name="item_code" value="<%= list.get("item_code", 0) %>"  class="wmax"/>
	        			</td>
						<th><p>판매가(아이폰)</p></th>
						<td class="brx">
							<input type="text" name="price_usd" value="<%= list.get("price_usd", 0) %>"  class="w60 r"/> $
						</td>
					</tr>
					<tr>
						<th><p>헤더파일</p></th>
						<td colspan="5" class="brx">
							<%= list.get("book_header", 0) %>
						</td>
					</tr>
					
					
					<tr>
						<th><p>큐북 원본파일</p></th>
						<td colspan="3">
							<input type="file" name="book_path_org" value="" class="input_file w200" />
						<%	if (!"".equals(list.get("book_path_org",0))) { %>
			        			<a href="/common/download_view.jsp?file_dir=<%= list.get("book_path_org",0) %>"><%= list.get("book_path_org",0) %></a>
						<%	} %>			        			
						</td>
						<th><p>파일용량</p></th>
						<td class="brx">
							<%= list.get("file_size", 0) %>
						</td>
					</tr>
					<tr>
						<th><p>샘플 원본파일</p></th>
						<td colspan="3">
							<input type="file" name="preview_book_path" value="" class="input_file w200" />
						<%	if (!"".equals(list.get("preview_book_path",0))) { %>
			        			<a href="/common/download_view.jsp?file_dir=<%= list.get("preview_book_path",0) %>"><%= list.get("preview_book_path",0) %></a>
						<%	} %>			        			
						</td>
						<th><p>샘플용량</p></th>
						<td class="brx">
							<%= list.get("preview_file_size", 0) %>
						</td>
					</tr>
					<tr>
						<th><p>큐북URL</p></th>
						<td colspan="3">
							<input type="text" name="book_url" value="<%= list.get("book_url", 0) %>" class="wmax" />
						</td>
						<th><p>다운로드</p></th>
						<td class="brx">
							<%= list.get("download_count", 0) %>
						</td>
					</tr>
					<tr>
						<th><p>샘플URL</p></th>
						<td colspan="3">
							<input type="text" name="preview_book_url" value="<%= list.get("preview_book_url", 0) %>" class="wmax" />
						</td>
						<th><p>다운로드</p></th>
						<td class="brx">
							<%= list.get("preview_download_count", 0) %>
						</td>
					</tr>
					<tr>
						<th><p>큐북DB <span class="remark">(안드로)</span></p></th>
						<td colspan="3">
							<input type="file" name="book_path_android" value="" class="input_file w200" />
						<%	if (!"".equals(list.get("book_path_android",0))) { %>
			        			<a href="/common/download_view.jsp?file_dir=<%= list.get("book_path_android",0) %>"><%= list.get("book_path_android",0) %></a>
						<%	} %>			        			
						</td>
						<th><p></p></th>
						<td class="brx">
							
						</td>
					</tr>
					<tr>
						<th><p>큐북DB <span class="remark">(아이폰)</span></p></th>
						<td colspan="3">
							<input type="file" name="book_path_ios" value="큐북DB" title="큐북DB" class="input_file w200" />
			        	<%	if (!"".equals(list.get("book_path_ios",0))) { %>
			        			<a href="/common/download_view.jsp?file_dir=<%= list.get("book_path_ios",0) %>"><%= list.get("book_path_ios",0) %></a>
						<%	} %>
						</td>
						<th><p></p></th>
						<td class="brx">
							
						</td>
					</tr>
					<tr>
						<th><p>최종수정일</p></th>
						<td>
							<%= list.get("up_date",0) %>
	        			</td>
						<th><p>최종수정자</p></th>
						<td>
							<%= list.get("up_user",0) %>
	        			</td>
						<th><p></p></th>
						<td class="brx">
							
						</td>
	        		</tr>
				</tbody>
				</table> 
					

			</div>


			<!-- 책소개 -->
			<div id="tabs-2" class="hidden mt15">

				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody id="list">
	        		<%-- <tr>
						<th><p>소개형식</p></th>
						<td class="brx">
							<%= StringUtil.makeRadio(code012, "intro_type", list.get("intro_type", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>소개이미지</p></th>
						<td class="brx">
							<input type="file" name="intro_image_url" value="" class="w300" />
							<%= list.get("intro_image_url",0) %>
						<%	if (!"".equals(list.get("intro_image_url",0))) { %>
			        			<img src="<%= list.get("intro_image_url",0) %>"/>
			        	<%	} %>
						</td>
					</tr> --%>
	        		<tr>
						<th><p>책소개</p></th>
						<td class="brx">
							<textarea name="intro" id="intro" style="width:860px; height:460px"><%= list.get("intro", 0) %></textarea>
						</td>
					</tr>
				</tbody>
				</table>

			</div>

			<!-- 목차정보 -->
			<div id="tabs-3" class="hidden mt15">

				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody id="list">
	        		<tr>
						<th><p>목차</p></th>
						<td class="brx">
							<textarea name="index_info" id="index_info" style="width:860px; height:460px"><%= list.get("index_info", 0) %></textarea>
						</td>
					</tr>
				</tbody>
				</table>

			</div>
			
			<!-- 저자정보 -->
			<div id="tabs-4" class="hidden mt15">

				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody id="list">
	        		<tr>
						<th><p>저자소개</p></th>
						<td class="brx">
							<textarea name="author_info" id="author_info" style="width:860px; height:460px"><%= list.get("author_info", 0) %></textarea>
						</td>
					</tr>
				</tbody>
				</table>

			</div>


			<!-- 리뷰 -->
			<div id="tabs-5" class="hidden mt15">

				<table width="100%" cellpadding="0" cellspacing="0" class="table_04 mt15">
				<colgroup>
					<col width="40px" />
					<col width="100px" />
					<col width="100px" />
					<col width="100px" />
					<col  />
					<col width="120px" />
					<col width="100px" />
				</colgroup>
				<thead>
				<tr>
					<th><p>No</p></th>
					<th><p>회원아이디</p></th>
					<th><p>회원명</p></th>
					<th><p>평점</p></th>
					<th><p>내용</p></th>
					<th><p>등록일</p></th>
					<th><p>삭제</p></th>
				</tr>
				</thead>
				<tbody id="reviewList">
				
			<% 	for (int i = 0; i < reviewList.size(); i++) {	%>
				<tr>
					<td><%= i+1 %></td>
					<td><%= reviewList.get("member_id", i) %></td>
					<td><%= reviewList.get("member_name", i) %></td>
					<td><%= reviewList.get("rate", i) %></td>
					<td class="l"><%= reviewList.get("review_info", i) %></td>
					<td><%= reviewList.get("init_date", i) %></td>
					<td><a href="#nohref" onclick="fnDeleteReview('<%= reviewList.get("member_id", i) %>', '<%= book_code %>')"><img src="/images/cms/ico_delete.gif"/></a></td>
				</tr>

			<%	} %>
				</tbody>
				</table>

			</div>
			


			<div class="mt20 mb10 c">
				<a href="./bookList.jsp"><img src="../images/btn_list.gif"/></a>
		<%	if ("U".equals(job_type)) { %>
				<a href="#nohref" onclick="fnSave()"><img src="../images/btn_update.gif" /></a>
				<a href="#nohref" onclick="fnDelete()"><img src="../images/btn_delete.gif" /></a>
		<%	} else if ("C".equals(job_type)) { %>
				<a href="#nohref" onclick="fnSave()"><img src="../images/btn_register.gif" /></a>
		<%	} %>
			</div>


			</form>


		</div>
	</div>
</div>

</body>
</html>
